package com.mdp.sms.service;

import com.mdp.core.entity.Tips;
import com.mdp.sms.api.SmsCodeServerService;
import com.mdp.sms.api.SmsSenderService;
import com.mdp.sms.api.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class DefaultSmsService implements  SmsService{
	@Autowired
	SmsCodeServerService smsCodeService;
	
	@Autowired
	public  SmsSenderService sss;
	
	/**
	 * 手机登录验证码发送
	 * @param mobile
	 * @return
	 */
	public Tips sendLoginValidCode(String mobile){
		String validCode=smsCodeService.createSmsCode(mobile, 6,"login");
		String msg=validCode +"为您的登录验证码，请于5分钟内填写。如非本人操作，请忽略本短信。";
		Tips tips=sss.send(0, "86", mobile, msg, "", "");
		return tips;
		
	}
	/**
	 * 注册时候的手机验证码发送
	 * @param mobile
	 * @return
	 */
	public Tips sendRegisterValidCode(String mobile){
		String validCode=smsCodeService.createSmsCode(mobile, 6,"register");
		String msg=validCode +"为您的登录验证码，请于5分钟内填写。如非本人操作，请忽略本短信。";
		Tips tips=sss.send(0, "86", mobile, msg, "", "");
		return tips;
		
	}
	/**
	 * 通用的手机验证码发送
	 * @param mobile
	 * @return
	 */
	public Tips sendCommonValidCode(String mobile){
		String validCode=smsCodeService.createSmsCode(mobile, 6,"common");
		String msg=validCode +"为您的手机验证码，请于5分钟内填写。如非本人操作，请忽略本短信。";
		Tips tips=sss.send(0, "86", mobile, msg, "", "");
		return tips;
		
	}
	/**
	 * 通用的手机验证码发送
	 * @param mobile
	 * @return
	 */
	public Tips sendValidCode(String mobile,String scene){
		String validCode=smsCodeService.createSmsCode(mobile, 6,scene);
		String msg=validCode +"为您的手机验证码，请于5分钟内填写。如非本人操作，请忽略本短信。";
		Tips tips=sss.send(0, "86", mobile, msg, "", "");
		return tips;
		
	}
	/**
	 * 验证手机或者验证码是否争确
	 * @param mobile
	 * @param smsCode
	 * @return
	 */
	public Tips validateSmsCode(String mobile,String smsCode,String scene){
		boolean right=smsCodeService.validateSmsCode(mobile, smsCode,scene); 
		Tips tips=new Tips("验证码正确");
		if(!right){
			tips.setErrMsg("验证码不正确");
		}
		return tips;
		
	}
	/**
	 * 验证手机或者验证码是否争确
	 * @param mobile
	 * @param smsCode
	 * @return
	 */
	public Tips validateSmsCode(String mobile,String smsCode){
		boolean right=smsCodeService.validateSmsCode(mobile, smsCode,"common"); 
		Tips tips=new Tips("验证码正确");
		if(!right){
			tips.setErrMsg("验证码不正确");
		}
		return tips;
		
	}
	 
}
